import sys
import json
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
from chia.types.condition_opcodes import ConditionOpcode
from chia.util.hash import std_hash
from clvm.casts import int_to_bytes
from functools import reduce
from chia.types.blockchain_format.program import Program
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import (  # standard_transaction
    puzzle_for_pk,
    calculate_synthetic_secret_key,
    DEFAULT_HIDDEN_PUZZLE_HASH,
)
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.util.bech32m import encode_puzzle_hash
from typing import Dict, List, Tuple, Optional, Union
from chia.consensus.coinbase import create_puzzlehash_for_pk
from chia.util.ints import uint32
from chia.util.keychain import Keychain, bytes_to_mnemonic, generate_mnemonic, unlocks_keyring,mnemonic_to_seed
from chia.wallet.derive_keys import master_sk_to_farmer_sk, master_sk_to_pool_sk, master_sk_to_wallet_sk


def skToHexStr(sk):
    skStr=str(sk)
    return "0x"+skStr[12:][:-1]

mnemonic=" ".join(sys.argv[1:])

seed = mnemonic_to_seed(mnemonic, "")

sk = AugSchemeMPL.key_gen(seed)

fingerprint = sk.get_g1().get_fingerprint()

firstSk=master_sk_to_wallet_sk(sk, uint32(0))

puzzleHash=create_puzzlehash_for_pk(master_sk_to_wallet_sk(sk, uint32(0)).get_g1())

address=encode_puzzle_hash(puzzleHash, '')

output = {
    "fingerprint":fingerprint,
    "master_secret_key":skToHexStr(sk),
    "master_public_key":"0x"+str(sk.get_g1()),
    "first_wallet_secrect_key":skToHexStr(firstSk),
    "first_wallet_public_key":"0x"+str(firstSk.get_g1()),
    "puzzleHash":"0x"+str(puzzleHash),
    "$address":address,
}

output["$fp"]=output["fingerprint"]
output["$$sk"]=output["master_secret_key"]
output["$$pk"]=output["master_public_key"]
output["$sk"]=output["first_wallet_secrect_key"]
output["$pk"]=output["first_wallet_public_key"]
output["$ph"]=output["puzzleHash"]

print(json.dumps(output))